package com.algorithm.string_and_array;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class ArraySolutionLC08 {
    public void rotate(int[][] matrix) {
        int i = 0;
        int j = matrix.length-1;
        while (i< matrix.length){
            re(i,j,matrix);
            i++;
            j--;
        }

        reLevel(matrix);

    }
    // 根据对角线反转
    private void re(int midx,int midy,int[][] matrix) {
        int i = midx;
        int j = midy;
        while (i < matrix.length && j > 0) {
            int tmp = matrix[midx][j - 1];
            matrix[midx][j - 1] = matrix[i + 1][midy];
            matrix[i + 1][midy] = tmp;
            i++;
            j--;
        }
    }
    // 根据中间反转
    private void reLevel(int[][] matrix){
        int sy = 0;
        int ey = matrix.length-1;
        while (sy<ey){
            for (int i = 0; i < matrix.length; i++) {
                int tmp = matrix[sy][i];
                matrix[sy][i] = matrix[ey][i];
                matrix[ey][i] = tmp;
            }
            sy++;
            ey--;
        }
    }

    @Test
    public void test(){
        int [][] matrix =  {{1,2,3,0},
                            {4,5,6,8},
                            {7,8,9,3},
                            {7,8,9,3}};
        rotate(matrix);
        log.info("this is result");
    }
}
